package com.shrct.businessprocess.product.impl;

import com.shrct.businessprocess.product.RCIdentifiableProductEntry;
import com.shrct.businessprocess.product.RCProductEntry;
import com.shrct.businessprocess.product.impl.RCProductEntryImpl;
import com.shrct.businessprocess.product.proxy.RCIdentifiableProductEntryProxy;
import com.shrct.businessprocess.purchase.RCProductInStockEvent;
import edu.fudan.mylang.pf.IGenericQuery;
import java.util.ArrayList;
import java.util.Date;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;

@Entity
@DiscriminatorValue("RCIDENTIFIABLEPRODUCTENTRY_TYPE")
public abstract class RCIdentifiableProductEntryImpl extends RCProductEntryImpl implements RCIdentifiableProductEntry {
  public RCIdentifiableProductEntryImpl() {
    super();
  }
  
  public String getEntityName() {
    String _sid = this.getSid();
    return _sid;
  }
  
  private Integer count = Integer.valueOf(1);
  
  public Integer getCount() {
    return this.count;
  }
  
  public RCIdentifiableProductEntry setCount(final Integer count) {
    this.count = count;
    return this;			
    
  }
  
  public Date getInstockDate() {
    IGenericQuery<RCProductInStockEvent> query=getObjectFactory().createGenericQuery(RCProductInStockEvent.class,"select e from com.shrct.businessprocess.purchase.impl.RCProductInStockEventImpl as e   where ((e.product) = (:this)) and  e.active = 1      ").setParameter("this",this);
    RCProductInStockEvent _uniqueResult = query.uniqueResult();
    Date _date = _uniqueResult==null?(Date)null:_uniqueResult.getDate();
    return _date;
  }
  
  public Iterable<RCProductEntry> allRelatedProducts() {
    ArrayList<RCProductEntry> _newArrayList = CollectionLiterals.<RCProductEntry>newArrayList(((RCProductEntry) this));
    return _newArrayList;
  }
  
  public RCIdentifiableProductEntryProxy toProxy() {
    com.shrct.businessprocess.product.proxy.RCIdentifiableProductEntryProxy proxy = new com.shrct.businessprocess.product.proxy.RCIdentifiableProductEntryProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
